package com.iflytek.uc.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.iflytek.uc.vo.Tree;
import com.iflytek.uc.vo.Tree.TreeState;

@Controller
@RequestMapping("/admin/entity")
public class EntityController {

	@RequestMapping("manage")
	public ModelAndView manage(String entityType) {
		ModelAndView mv = new ModelAndView("entity/manage");
		mv.addObject("entityType", entityType);
		return mv;
	}
	
	@RequestMapping("tree")
	@ResponseBody
	public List<Tree> tree(String entityType, String id) {
		List<Tree> nodes = null;
		if (StringUtils.isEmpty(id)) {
			nodes = getAllEntityNodes(entityType);
		}
 		return nodes;
	}

	private List<Tree> getAllEntityNodes(String entityType) {
		Tree tree = new Tree();
		tree.setAttributes(null);
		tree.setChecked(false);
		tree.setChildren(null);
		//tree.setIconCls("");
		tree.setId("00000000000000000000000000000000");
		tree.setState(TreeState.closed);
		tree.setText("所有\"单位\"");
		
		List<Tree> list = new ArrayList<Tree>();
		list.add(tree);
		
		return list;
	}
}
